package com.daiqee.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.daiqee.controller.support.CommonsController;
import com.daiqee.pojo.Train;
import com.daiqee.service.impl.EmployeeService;
import com.daiqee.service.impl.StaffTrainService;

/**
 * 员工培训
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V2.1
 * @author RichardTang 
 * @date: 2018年5月7日 下午5:55:38
 * @package com.daiqee.handler
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
@Controller
@RequestMapping("human-resource/staff-train")
public class StaffTrainController extends CommonsController<Train>{
	
	@Autowired
	private StaffTrainService staffTrain;
	
	@Autowired
	private EmployeeService employeeService;
	
	@Override
	public Object warpperQueryMethod(Train train, String dateScope, EntityWrapper<Train> ew, Page<Train> page) {
		ew = new EntityWrapper<Train>(train);
		if(dateScope != null && StringUtils.isNotBlank(dateScope)) {
			String[] trainDate = dateScope.split(" - ");
			ew.ge("train_start_date", trainDate[0]);
			ew.le("train_start_date", trainDate[1]);
		}
		return staffTrain.selectPage(page, ew);
	}
	
	@Override
	public boolean warpperAddMethod(Train train) throws Exception {
		if(train.getTrainParticipantsId().isEmpty()) {
			train.setTrainParticipantsId("无人参加");
			train.setTrainShouldPeoples(0);
		}
		train.setTrainStatus(1);
		train.setTrainActualPeoples(0);
		return staffTrain.insert(train);
	}
	
	@Override
	public boolean warpperDeleteMethod(String ids, List<String> idList) {
		staffTrain.deleteBatchIds(idList);
		return employeeService.deleteBatchIds(idList);
	}
}
